home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / callback.001 / callback~ / callback / lib / dbase / getstate.c < prev    next >
C/C++ Source or Header  |  1996-07-22  |  1KB  |  31 lines

  1.  
  2. #include "dbase.p"
  3.  
  4. int getstate(int *state, unsigned *userid)
  5. {
  6.     register FILE
  7.         *inf;
  8.     int
  9.         x;
  10.  
  11.     *state = -1;                        /* assume no statefile */
  12.  
  13.     if ((inf = fopen(filename[the_statefile], "r")))
  14.     {
  15.         if ((x = fscanf(inf, "%d %d", state, userid)) != 2)
  16.                log(log_off, "invalid state file \"%s\": %d items read, "
  17.                      "state: %d, username: %s", 
  18.                          filename[the_statefile], x, *state, username(*userid));
  19.         fclose (inf);
  20.  
  21.     if (x != 2 || ageof(filename[the_activefile]) > maxage)
  22.             *state = -2;                    /* force enable: too old/invalid */
  23.     }
  24.  
  25.     return (*state);                        /* return the state */
  26.                                             /* -2: expiry, force enable     */
  27.                                             /* -1: no state file, waiting   */
  28.                                             /*  0: states exhaused  */
  29.                                             /* >0: retry state      */
  30. }
  31.